package se.study.thread;

import java.util.concurrent.*;

/**
 * @Author: tiger
 * @Date:2018/5/14
 * @Description:线程池Study
 */
public class Executor {
    public static void main(String[] args) {
        ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(5, 5, 5000L, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(5), Executors.defaultThreadFactory());
        System.out.println(Thread.currentThread().getId());
        Task task = new Task();
        threadPoolExecutor.execute(task);
        threadPoolExecutor.execute(task);

        System.out.println("线程池曾经创建过的最大线程数量：" + threadPoolExecutor.getLargestPoolSize());
        System.out.println("线程池在运行过程中已完成的任务数量：" + threadPoolExecutor.getTaskCount());
        System.out.println("线程池的最大线程数量：" + threadPoolExecutor.getMaximumPoolSize());
        System.out.println("获取活动的线程数：" + threadPoolExecutor.getActiveCount());

//        threadPoolExecutor.shutdown();

    }

    static class Task implements Runnable {

        @Override
        public void run() {
            for (int i = 0; i < 100; i++) {
                System.out.println("task..." + Thread.currentThread().getId());
            }
        }
    }

}
